package com.ming.mallchat.common.common.thread;

import lombok.AllArgsConstructor;
import java.util.concurrent.ThreadFactory;

/**
 * 修饰器模式
 * @author 86150
 * @date 2023/09/27
 */
@AllArgsConstructor
public class MyThreadFactory implements ThreadFactory {

    private static final MyUncaughtExceptionHandler MY_UNCAUGHT_EXCEPTION_HANDLER = new MyUncaughtExceptionHandler();

    private ThreadFactory threadFactory;

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = threadFactory.newThread(r);//执行spring线程自己的创建逻辑
        thread.setUncaughtExceptionHandler(MY_UNCAUGHT_EXCEPTION_HANDLER);
        return thread;
    }
}
